package edu.gzist.cs.service;

import edu.gzist.cs.model.User;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@Service
public class UserService {

    private final RestTemplate restTemplate;

    public UserService(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    public User getUserById(int userId) {
        String url = "https://jsonplaceholder.typicode.com/users/" + userId;
        return restTemplate.getForObject(url, User.class);
    }

    public User createUser(User user) {
        String url = "https://jsonplaceholder.typicode.com/users";
        return restTemplate.postForObject(url, user, User.class);
    }

    public void updateUser(int userId, User user) {
        String url = "https://jsonplaceholder.typicode.com/users/" + userId;
        restTemplate.put(url, user);
    }

    public void deleteUser(int userId) {
        String url = "https://jsonplaceholder.typicode.com/users/" + userId;
        restTemplate.delete(url);
    }
}